import { createRouter, createWebHashHistory, RouterView } from "vue-router";

const router = createRouter({
  scrollBehavior: () => ({ top: 0 }),
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      component: () => import("@/components/XtxLayout.vue"),
      children: [
        {
          path: "",
          component: () => import("@/views/home/HomePage.vue"),
        },
          {
            path: "category/:id",
            component: () => import("@/views/category/TopCategoryPage.vue")
          },
          {
            path: "category/sub/:top/:sub",
            component: () => import("@/views/category/SubCategoryPage.vue")
          },
          {
            path:"goods/:id",
            component: ()=> import("@/views/goods/GoodsDetailPage.vue")
          },
          {
            path:"cart",
            component: ()=> import("@/views/cart/CartPage.vue")
          },
          {
            path:"checkout/order",
            component: ()=>import("@/views/pay/CheckoutPage.vue")
          },
          {
            path: "checkout/pay",
            component: () => import("@/views/pay/PayPage.vue"),
          },
          {
            path: "pay/callback",
            component: () => import("@/views/pay/PayResultPage.vue"),
          },
          {
            path: "member",
            component: () => import("@/components/XtxMemberLayout.vue"),
            redirect: "/member/home",
            children: [
              {
                path: "home",
                component: () => import("@/views/member/home/HomeMemberPage.vue"),
              },
              {
                path: "order",
                component: h(RouterView),
                children:[
              {
                path:"",
                component: () => import("@/views/member/order/OrderListPage.vue"),
              },
              {
                path: ":id",
                component: () => import("@/views/member/order/OrderDetailPage.vue"),
              },
                ]
               
              },
            
            ],
          }
      ],
    },
    {
      path: "/login",
      component: () => import("@/views/login/LoginPage.vue"),
    },
    {
      path:"/login/callback",
      component:() => import("@/views/login/QQLoginBack.vue"),
      beforeEnter:()=>{
        //如果没有进行QQ扫码授权
        if(!window.QC.Login.check()){
          //不能进入该页面
          return false
        }
        return true;
      }
    }
  ],
});

export default router;